package sort;

import java.util.Arrays;

/**
 * @program: javase
 * @description: 插入排序
 * @author: luolidong
 * @create: 2021-07-06 11:18
 * @version: 1.0
 */
public class Sort {
    public int[] insertSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            int cur = arr[i];
            int j = i;
            if (arr[j - 1] >= cur) {
                continue;
            }
            while (j - 1 >= 0 && arr[j - 1] < cur) {
                arr[j] = arr[j - 1];
                j--;
            }
            arr[j] = cur;

        }
        return arr;
    }

    public static void main(String[] args) {
        int[] ints = {5, 4,3,2,1,6};
        int[] ints1 = new Sort().insertSort(ints);
        System.out.println(Arrays.toString(ints1));
    }
}
